<?php
/*
 * @分消商城
 * @功能说明：用户管理中心
 * @更新说明：暂无更新
 * @文件名 UserController.class.php
 * @编码 UTF-8
 * @创建时间 2016-3-8 下午2:06:50
 * @创建人 XING
 */

namespace dg\Controller;
use Think\Controller;
class ServiceController extends ApibaseController
{
    /*
      * 香格丽雅_预约服务
      * @date: 2016-5-24 下午1:47:53
      * @editor: yanyan
      */
    public function index(){
        $page = I('get.page') ?: 1;
        $perpage = 10;$url = '';
        $url = $output = $outtype = array();
        $list = M('CustService');
        if(I('get.cust_name')){
            $list = $list->where('cust_name LIKE "%'.I('get.cust_name').'%"');
        }
        if(I('get.service_title')){
        	$list = $list->where('service_title LIKE "%'.I('get.service_title').'%"');
        }
        if(in_array(I('get.service_status'),array('0',1,-1))){
            $list = $list->where(array('service_status'=>I('get.service_status')));
            $url['service_status'] = I('get.service_status');
        }
        $getService = $list
            ->order(array('add_at'=>'DESC'))->page($page,$perpage)->select();
        $this->assign('page',setPage($list->count(),$perpage,$page,'?'.http_build_query($url)));
        $this->assign('getData',$getService);
        $this->display('service/index');
    }

    /*
     * 香格丽雅_预约订单
     * @date: 2016-5-28 下午13:02:55
     * @editor: XING
     */
    public function order(){
    	$page = I('get.page') ?: 1;
    	$perpage = 10;$url = '';
    	$url = $output = $outtype = array();
    	$list = M('ServiceOrder');
    	if(I('get.goods_title')){
    		$list = $list->where('goods_title LIKE "%'.I('get.goods_title').'%"');
    	}
    	$getService = $list
    				->order(array('add_at'=>'DESC'))->page($page,$perpage)->select();
    	$this->assign('page',setPage($list->count(),$perpage,$page,'?'.http_build_query($url)));
    	$this->assign('getData',$getService);
    	$this->display('service/order');
    }
   
    /*
      * 香格丽雅_预约服务审核(检查是否已支付)
      * @date: 2016-5-24 下午1:47:53
      * @editor: yanyan
      */
    public function check_service(){
        if(I('post.dosubmit')) {
            //处理预约服务支付状态
            $effectId = M('CustService')->where(array('service_id' => I('post.id')))
		              ->setField(array(
		                    'service_status' => trim(I('post.status')),
		                    'remark' => trim(I('post.remark')),
		                    'update_at' => time(),
		                    'pay_at' => time()
		                ));
            if($effectId){
                $this->showtips('预约服务支付状态更新成功');
            }else{
                $this->showtips('操作失败');
            }
        }
        if(I('get.id')){
            $getData = M('CustService')
                ->where(array('service_id'=>I('get.id')))->find();
            $this->assign('getData',$getData);
        }
        $this->display('service/check_service');
    }
}
